import cloud from "@lafjs/cloud";

const db = cloud.database();
import { resultOk, getPermissions, resultFail } from "@/utils";
const adminDbName = "admin-staff";
export default async function (ctx: FunctionContext) {
  if (!ctx.user) {
    return resultFail("用户未登陆", -2);
  }
  const { data: admin } = await db
    .collection(adminDbName)
    .where({ _id: ctx.user.uid })
    .getOne();
  delete admin["password"];
  const { permissions } = await getPermissions(admin._id);
  return resultOk({
    ...admin,
    expire: ctx.user.expire,
    permissions
  });
}
